package com.coderush.admin.sys.controller;

import com.coderush.admin.core.response.Result;
import com.coderush.admin.sys.model.dto.MenuAddDto;
import com.coderush.admin.sys.model.vo.MenuLeftVo;
import com.coderush.admin.sys.service.MenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * PackageName com.coderush.admin.sys.controller
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName MenuController
 * @Date 2025/9/2
 * @Description TODO
 */
@RestController
@RequestMapping("/sys/menu")
@Validated  // 类级别添加，用于方法参数校验
@Tag(name = "菜单管理", description = "菜单管理")
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * 查询左侧菜单
     */
    @Operation(summary = "查询左侧动态菜单", description = "查询左侧动态菜单")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @RequestMapping("/findLeftMenu")
    public Result<List<MenuLeftVo>> findLeftMenu() throws Exception {

        List<MenuLeftVo> menuList = menuService.findLeftMenu();

        return Result.buildSuccess(menuList);
    }


    /**
     * 添加菜单
     */
    @Operation(summary = "添加菜单", description = "添加菜单")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "操作成功"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/add")
    public Result<Boolean> add(@Valid @RequestBody MenuAddDto addDto) throws Exception {

        Boolean result = menuService.add(addDto);

        return Result.buildSuccess(result);
    }

}